package com.drama.util;

import java.math.BigDecimal;

public class ToolUtil {


    public static String formatFileSize(Long size) {
        String sizeName = null;
        if(1024*1024 > size && size >= 1024 ) {
            sizeName = String.format("%.2f",size.doubleValue()/(1024)) + "MB";
        }else if(1024*1024*1024 > size && size >= 1024*1024 ) {
            sizeName = String.format("%.2f",size.doubleValue()/(1024*1024)) + "GB";
        }else if(size >= 1024*1024*1024 ) {
            sizeName = String.format("%.2f",size.doubleValue()/(1024*1024*1024)) + "TB";
        }else {
            sizeName = size.toString() + "KB";
        }
        return sizeName;
    }

    public static String formatFileSizeGB(Long size) {
        String sizeName = null;
         sizeName = String.format("%.2f",size.doubleValue()/(1024*1024)) + "GB";
        return sizeName;
    }


    public static String formatFileSizeGB(String size) {
        return  formatFileSizeGB(new BigDecimal(size).longValue());
    }
    public static String formatFileSize(String size) {
        return  formatFileSize(new BigDecimal(size).longValue());
    }

}
